<template>
	<van-popup position="bottom" :show="show">
		<van-picker show-toolbar :columns="getColumns(colums)"
			@confirm="onConfirm" @cancel="onCancel" />
	</van-popup>
</template>

<script>
	export default{
		name:"picker-view",
		props:{
			list:{	// 下拉数据
				type:Array,
				default(){
					return {}
				}
			},
		},
		data(){
			return{
				colums:[],
				show:false,
				value:"",
			}
		},
		methods:{
			open(){
				this.show = !this.show;
			},
			/**
			 * 确认
			 */
			onConfirm(e){
				this.value = e.value;
				this.$emit("confirm",this.value)
				this.onCancel();
			},
			
			/**
			 * 隐藏
			 */
			onCancel(){
				this.show = false;
			}
		},
		computed:{
			getColumns() {
				return function(list, type) {
					if (!list || list.length == 0) return []
					let arr = []
						arr = list.map(item => item.sort);
					return arr;
				}
			},
		},
		watch:{
			list:{
				immediate:true,
				deep:true,
				handler(value){
					this.colums = value || [];
					console.log(this.colums)
				}
			}
		}
	}
</script>

<style>
</style>